% Program: Unrestricted Descent Performance Analysis Program

% Calls: FUNCTION   fdescent_06 
% Requires an aircraft file  (e.g.,eclipse500New_class.m)
%     
% Assumes all engines operate normally 
% This file computes an unrestricted (continuous) descent profile 
% Characteristics of the aircraft are loaded by an aircraft file
%
% Programmer: Toni Trani
% Sep. 16, 2006

% Inputs:

% An aircraft file containing the relevant performance characteristics of
% the vehicle to be modeled (e.g.,eclipse500New_class.m)

% Outputs:
% An aircraft state vector y with the following elements:

% y(1) - aircraft altitude (m)
% y(2) - aircraft weight (N)
% y(3) - distance traveled along the flight path (m)
% y(4) - distance traveled in the horizontal plane (m)

% Define global variables (to be shared across other functions and routines)

clear all

global g mass rhos hcruise deltaTemp

% Enter aircraft file desired - reads a file with aircraft characteristics
% eclipse500New_class
% regionalJetDescent
% AirbusA380_class                    % aircraft file used
boeing737Class
% boeing777_class_2011

h_TOD = 35000/3.28;            % initial altitude (m) - at Top of Descent Point (TOD)
mass_TOD = 60000;               % mass at TOD point (kg)
rhos = 1.225;                          % sea level density (kg/m-m-m)
deltaTemp = 0;                        % ISA + deltaTemp conditions for analysis (deg. Kelvin)
g=9.81;

Mass_init = mass_TOD*g;         % Initial aircraft weight (Newtons) at TOD point

% Define Initial Conditions of the Problem
%
% Four state variables comprise this problem as explained in class
%
% y(1) - aircraft altitude (m)
% y(2) - aircraft weight (N)
% y(3) - distance traveled along the flight path (m)
% y(4) - distance traveled in the horizontal plane (m)

yN = [h_TOD  Mass_init  0 0];	% Vector of initial values of state variables	

to = 0.0;				% to is the initial time to solve this equation (s)
tf = 3600.0;			% tf is the final time (s)
Ttime = [to tf];		% Simulation span time

% Invoke the ordinary differential equation solver (stiff ODE)
% 
% This part of the code integrates numerically the equations of motion of the aircraft in climb and derives an array variable
% y that contains three state variables for altitude, weight and distance traveled by the aircraft in climb

options = odeset('RelTol',1e-4);                              % to control the tolerance of the ODE solver
[t,y] = ode15s('fdescent_06',Ttime,yN,options);           % calls te ODE solver

% This ends the climb analysis procedure

% Calculate the rate of descent as the gradient of y(1) as a function of time
% (t)

rod=gradient(y(:,1),t);         % rate of descent (meters/second)

figure
plot(y(:,1),rod*60,'o-b')			% plots altitude vs rate of climb
ylabel('Rate of Descent (meters/min)','fontsize',24)
xlabel('Altitude (meters)','fontsize',24)
grid

% Plot the results of the numerical integration procedure

k_km2nm = 1/1.852;          % convert km to nm
k_m2FL = 3.28/100;          % converts meters to FL (or feet x 100)

figure
plot(y(:,4)/1000*k_km2nm,y(:,1)*k_m2FL,'o-b')			% plots distance vs altitude
xlabel('Distance (nm)','fontsize',24)
ylabel('Altitude (feet x 100)','fontsize',24)
grid

figure
plot(y(:,4)/1000,y(:,1),'o-')                                           % plots distance vs altitude
xlabel('Distance (km.)','fontsize',24)
ylabel('Altitude (m.)','fontsize',24)
grid
                                                                                                                                                                                                                                                 
figure
plot(t,y(:,1),'o-r')                                                         % plots altitude vs time
xlabel('Time (s.)','fontsize',24)
ylabel('Altitude (m.)','fontsize',24)
grid

figure
plot(t,y(:,4)/1000,'o-')                                                    % plots a time-space diagram
xlabel('Time (s.)','fontsize',24)
ylabel('Distance (km.)','fontsize',24)
grid

% Plot distance vs. Fuel Consumed

figure
plot(y(:,4)/1000,y(:,2),'o-')                                                    % plots a time-space diagram
xlabel('Distance (km)','fontsize',24)
ylabel('Aircraft Weight (N)','fontsize',24)
grid


